﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace GameStudio.Common.Serilization
{
    public static class SerilizationHelper
    {
        public static void Serilize(this object objectToBeSerilized, string path)
        {
            XmlSerializer serializer = new XmlSerializer(objectToBeSerilized.GetType());
            StreamWriter textWriter = new StreamWriter(path);
            serializer.Serialize(textWriter, objectToBeSerilized);
            textWriter.Close();
        }

        public static T DeSerialize<T>(this T objectToDeserilizeIn, string path)
            where T : class, new()
        {
            XmlSerializer deserializer = new XmlSerializer(objectToDeserilizeIn.GetType());
            StreamReader textReader = new StreamReader(path);
            objectToDeserilizeIn = (T)deserializer.Deserialize(textReader);
            textReader.Close();
            return objectToDeserilizeIn;
        }
    }
}
